//
//  SafePushViewController.m
//  objective_c_language
//
//  Created by 王玉龙 on 2018/6/20.
//  Copyright © 2018年 longlong. All rights reserved.
//

#import "SafePushViewController.h"

@interface SafePushViewController ()

@end

@implementation SafePushViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = Color_Purple;
    button.frame = CGRectMake(100, 100, 100, 32);
    button.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    button.titleEdgeInsets = UIEdgeInsetsMake(0, 16, 0, 0);
    [button setTitle:@"push" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(pushButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't add self as subview'
- (void)pushButtonClick:(UIButton *)sender
{
    UIViewController *vc1 = [[UIViewController alloc] init];
    UIViewController *vc2 = [[UIViewController alloc] init];
    UIViewController *vc3 = [[UIViewController alloc] init];
    
    
    [self.navigationController pushViewController:vc1 animated:NO];
    [self.navigationController pushViewController:vc2 animated:YES];
    [self.navigationController pushViewController:vc3 animated:YES];
}

/*
 https://www.jianshu.com/p/22aa0ca51cd8
 
 导致转场异常的根本原因是上一个次操作还没执行结束就开始执行下一个操作, 同步执行了多个转场操作, 根据私有属性wasLastOperationAnimated判断上一个操作是否还在动画中, 对于上一个次操作还没执行结束就开始执行下一个操作的case, 直接clear之前的转场操作, 但clear操作不能在发送“转场请求”时执行, 时机太早UINavigationController还没进行defer transition的处理, 这里需要在UINavigationController进行defer transition的处理失败后并在触发转场动画前进行clear(vc已入栈, 只clear转场的动画), 即思路二中函数调用的时机, 在其中进行非正常转场的clear操作.

 */

@end
